***** OPEN OUTPUT LOG FILE FOR APPENDIX D ANALYSES: "HARDIWRING MUTUAL COMMITTMENT" *****



*log "C:\Users\gk57526\Dropbox\Confirmation Dynamics Project (Jason Byers)\Appointee Tenure Project\Jason Byers\March 2023\DART (PRQ)\Output\Hardwiring Committment.APPENDIX D.04-21-2023.smcl" 

log using "C:\Users\Jason\Dropbox\Jason Byers\Co-Authored Projects\Projects with George Krause\Krause Projects\Confirmation Dynamics Project\Appointee Tenure Project\Jason Byers\March 2023\DART (PRQ)\Output\Hardwiring Committment.APPENDIX D.04-21-2023.smcl", replace




**** APPENDIX D STATISTICAL ANALYSES: 'LOYAL LIEUTENTANT' ADDITIVE/UNCONDITIONAL EFFECT OF PRESIDENTIAL LOYALTY ON APPOINTEE TENURE [SANS INTERACTION TERMS WITH PRESIDENTIAL POLICY PRIORITY BINARY INDICATOR] ***




** RETRIEVE SINGLE EVENT RECORDS DATABASE [N = 860 APPOINTEE OBSERVATIONS: 831 UNCENSORED OBSERVATIONS; 29 CENSORED OBSERVATIONS] **

use "C:\Users\Jason\Dropbox\Jason Byers\Co-Authored Projects\Projects with George Krause\Krause Projects\Confirmation Dynamics Project\Appointee Tenure Project\Jason Byers\March 2023\DART (PRQ)\Data\Krause and Byers.SRD.06-03-2022.dta", replace





** GENERATE CENSORING VARIABLE FOR HOLDOVER APPOINTEES SERVING BETWEEN/ACROSS ADMINISTRATIONS [=1]; UNCENSRED OBSERVATIONS [=0] ** 

gen singleadmin_service=1 if holdover==0
*
replace singleadmin_service=0 if holdover==1
*
*
tab singleadmin_service


** SET FOR SURVIVAL DATA WITH A SINGLE RECORD PER APPOINTEE OBSERVATION [N = 860: UNCENSORED N = 831; CENSORED N = 29] ** 
stset okapptdur, failure(singleadmin_service)
*
*
*
*
*
*
*
*

*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************





*** APPENDIX D SURVIVAL REGRESSION ANALYSES: COX SEMIPARAMETRIC & WEIBULL PARAMETRIC MODELS ****




******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************




**** APPENDIX D REGRESSION MODELS: 'LOYAL LIEUTENTANT' ADDITIVE/UNCONDITIONAL EFFECT OF PRESIDENTIAL LOYALTY ON APPOINTEE TENURE [SANS INTERACTION TERMS WITH PRESIDENTIAL POLICY PRIORITY BINARY INDICATOR]  ***



**** MODEL D1: COX MODEL [OMISSION OF BOTH AGENCY AND PRESIDENTIAL ADMINISTRATION FIXED EFFECTS: CLUSTER-ADJUSTED STANDARD ERRORS BY AGENCY] ****

stcox   zloyalmedian soubinaryagency2nom  zpecompmedian  zmecompmedian   toplevel2   presagencyideolalign  presagencyideolopposed subagencydesign standaloneagencydesign  okstartsenpolarizationmean okstartfilipresdistance   okcrossover okstartpresapp  okstartunemployment  i.okstartadyr  ,  hr vce(cluster sbagency)
*
estat ic

estimates store modelD1


*** COMPUTE Figure D2: Interquartile Increase Marginal Effect Change of Appointee Loyalty on the HAZARD RATIO of APPOINTEE TENURE {ADDITIVE EFFECT} {{4 [MD1−MD4] × 1 Horizontal Point Estimates and 95% CIs}}. ****
** NOTE: IQR = 1.3653231 [0.9692858 - (-0.3960373)]




** ONE INTERQUARTILE RANGE MARGINAL EFFECT INCREASE IN APPOINTEE LOYALTY DIFFERENTIAL BETWEEN POLICY PRIORITY AGENCY VERSUS NON-POLICY PRIORITY AGENCY [FIGURE D2] **



lincomest zloyalmedian*1.3653231, eform(hr)
matrix modelD1zloyal = r(table)
mat list modelD1zloyal
*




******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************



**** MODEL D2: COX MODEL [INCLUSION OF BOTH AGENCY AND PRESIDENTIAL ADMINISTRATION FIXED EFFECTS: CLUSTER-ADJUSTED STANDARD ERRORS BY AGENCY] ****

stcox   zloyalmedian soubinaryagency2nom  zpecompmedian  zmecompmedian   toplevel2   presagencyideolalign  presagencyideolopposed subagencydesign standaloneagencydesign  okstartsenpolarizationmean okstartfilipresdistance   okcrossover okstartpresapp  okstartunemployment  i.okstartadyr  i.sbagency reagan bush41 clinton bush43,  hr vce(cluster sbagency)
*
estat ic

estimates store modelD2


*** COMPUTE Figure D2: Interquartile Increase Marginal Effect Change of Appointee Loyalty on the HAZARD RATIO of APPOINTEE TENURE {ADDITIVE EFFECT} {{4 [MD1−MD4] × 1 Horizontal Point Estimates and 95% CIs}}. ****
** NOTE: IQR = 1.3653231 [0.9692858 - (-0.3960373)]

lincomest zloyalmedian*1.3653231, eform(hr)
matrix modelD2zloyal = r(table)
mat list modelD2zloyal




*******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************





**** MODEL D3: WEIBULL MODEL [OMISSION OF BOTH AGENCY AND PRESIDENTIAL ADMINISTRATION FIXED EFFECTS: CLUSTER-ADJUSTED STANDARD ERRORS BY AGENCY] ****

streg   zloyalmedian soubinaryagency2nom  zpecompmedian  zmecompmedian   toplevel2   presagencyideolalign  presagencyideolopposed subagencydesign standaloneagencydesign  okstartsenpolarizationmean okstartfilipresdistance   okcrossover okstartpresapp okstartunemployment  i.okstartadyr,   distribution(weibull)  hr vce(cluster sbagency)
*
estat ic

estimates store modelD3


*** COMPUTE Figure D2: Interquartile Increase Marginal Effect Change of Appointee Loyalty on the HAZARD RATIO of APPOINTEE TENURE {ADDITIVE EFFECT} {{4 [MD1−MD4] × 1 Horizontal Point Estimates and 95% CIs}}. ****
** NOTE: IQR = 1.3653231 [0.9692858 - (-0.3960373)]

lincomest zloyalmedian*1.3653231, eform(hr)
matrix modelD3zloyal = r(table)
mat list modelD3zloyal



**** COMPUTE Figure D3: Interquartile Increase Marginal Effect Change of Appointee Loyalty on the MEDIAN NUMBER OF DAYS OF APPOINTEE TENURE {ADDITIVE EFFECT} {{4 [MD1−MD4] × 1 Horizontal Point Estimates and 95% CIs}.
** NOTE: IQR = 1.3653231 [0.9692858 - (-0.3960373)]

** Re-Estimate Model D3  with 'manual' interaction variable **
streg   zloyalmedian soubinaryagency2nom  zpecompmedian  zmecompmedian   toplevel2   presagencyideolalign  presagencyideolopposed subagencydesign standaloneagencydesign  okstartsenpolarizationmean okstartfilipresdistance   okcrossover okstartpresapp okstartunemployment  i.okstartadyr, distribution(weibull) hr vce(cluster sbagency)

estimate store modelD3a


margins, predict(median time) at(zloyalmedian=(-0.3960373 0.9692858))

** Generate Differential Predicted Median Survival Time of Senate Committee Stage of Confirmation Process -- Based on Interquartile Differential  **
margins, predict(median time) at(zloyalmedian=(-0.3960373 0.9692858))  contrast(atcontrast(r))
matrix modelD3azloyal = r(table)
mat list modelD3azloyal



estimates restore modelD3a

margins, predict(median time) at(zloyalmedian=(-0.6451644 1.711348))
margins, predict(median time) at(zloyalmedian=(-0.6451644 1.711348))  contrast(atcontrast(r))

matrix modelD3bzloyal = r(table)
mat list modelD3bzloyal




******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************




**** MODEL D4: WEIBULL MODEL [INCLUSION OF BOTH AGENCY AND PRESIDENTIAL ADMINISTRATION FIXED EFFECTS: CLUSTER-ADJUSTED STANDARD ERRORS BY AGENCY] ****

streg   zloyalmedian  soubinaryagency2nom  zpecompmedian  zmecompmedian   toplevel2   presagencyideolalign  presagencyideolopposed subagencydesign standaloneagencydesign  okstartsenpolarizationmean okstartfilipresdistance   okcrossover okstartpresapp okstartunemployment  i.okstartadyr  i.sbagency reagan bush41 clinton bush43, distribution(weibull) hr vce(cluster sbagency)
*
estat ic

estimates store modeld4



*** COMPUTE Figure D2: Interquartile Increase Marginal Effect Change of Appointee Loyalty on the HAZARD RATIO of APPOINTEE TENURE {ADDITIVE EFFECT} {{4 [MD1−MD4] × 1 Horizontal Point Estimates and 95% CIs}}. ****
** NOTE: IQR = 1.3653231 [0.9692858 - (-0.3960373)]
estimates restore modeld4

*there was an interaction in the lincomest between soubinaryagency2nom and zloyalmedian didn't seem to be needed based on the above code

lincomest c.zloyalmedian*1.3653231, eform(hr)
matrix modelD4zloyal = r(table)
mat list modelD4zloyal




**** COMPUTE Figure D3: Interquartile Increase Marginal Effect Change of Appointee Loyalty on the MEDIAN NUMBER OF DAYS OF APPOINTEE TENURE {ADDITIVE EFFECT} {{4 [MD1−MD4] × 1 Horizontal Point Estimates and 95% CIs}.
** NOTE: IQR = 1.3653231 [0.9692858 - (-0.3960373)]

** Re-Estimate Model D4  with 'manual' interaction variable **
streg   zloyalmedian soubinaryagency2nom   zpecompmedian  zmecompmedian   toplevel2   presagencyideolalign  presagencyideolopposed subagencydesign standaloneagencydesign  okstartsenpolarizationmean okstartfilipresdistance   okcrossover okstartpresapp okstartunemployment  i.okstartadyr i.sbagency reagan bush41 clinton bush43, distribution(weibull) hr vce(cluster sbagency)

estimates store modelD4a

margins, predict(median time) at(zloyalmedian=(-0.3960373 0.9692858))

** Generate Differential Predicted Median Survival Time of Senate Committee Stage of Confirmation Process -- Based on Interquartile Differential [corresponding to Differential Marginal Hazard Ratio Estimates] **
margins, predict(median time) at(zloyalmedian=(-0.3960373 0.9692858))  contrast(atcontrast(r))

matrix modelD4azloyal = r(table)
mat list modelD4azloyal



estimates restore modelD4a

margins, predict(median time) at(zloyalmedian=(-0.6451644 1.711348))
margins, predict(median time) at(zloyalmedian=(-0.6451644 1.711348))  contrast(atcontrast(r))

matrix modelD4bzloyal = r(table)
mat list modelD4bzloyal


*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************
*****************************************************************************************************************************************************************************************



*Figure D1

matrix pointmodel = modelD1zloyal[1,1], modelD2zloyal[1,1], modelD3zloyal[1,1], modelD4zloyal[1,1]

*
matrix cimodel = (modelD1zloyal[5,1], modelD2zloyal[5,1], modelD3zloyal[5,1], modelD4zloyal[5,1] \ modelD1zloyal[6,1], modelD2zloyal[6,1], modelD3zloyal[6,1], modelD4zloyal[6,1])

coefplot (matrix(pointmodel), ci((cimodel))), grid(none) xline(1, lcolor(red%40) lpattern(dash)) xtitle("Hazard Ratio", size(small) margin(t=2)) ylabel(1 "Model D1"  2 "Model D2"  3 "Model D3" 4 "Model D4", labsize(small) noticks) mlabel format(%9.3f) mlabposition(12) mlabsize(vsmall) xlabel(0(1)2, angle(0) labsize(small) format(%9.1f)) msymbol(o) mcolor(black) msize(small) title("FIGURE D1", size(small)) ciopts(lcolor(black)) legend(off) subtitle("Marginal Differential Effect of Presidential Loyalty on Appointee Tenure Hazard" "[Unconditional Additive Effect]", size(small))

graph save "Graph" "C:\Users\Jason\Dropbox\Jason Byers\Co-Authored Projects\Projects with George Krause\Krause Projects\Confirmation Dynamics Project\Appointee Tenure Project\Jason Byers\March 2023\DART (PRQ)\Graphics\FigureD1.gph", replace





******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************



*Figure 2

matrix pointmodel1 = modelD3azloyal[1,1], modelD3bzloyal[1,1], modelD4azloyal[1,1], modelD4bzloyal[1,1]

*
matrix cimodel1 = (modelD3azloyal[5,1], modelD3bzloyal[5,1], modelD4azloyal[5,1], modelD4bzloyal[5,1] \ modelD3azloyal[6,1], modelD3bzloyal[6,1], modelD4azloyal[6,1], modelD4bzloyal[6,1])

coefplot (matrix(pointmodel1), ci((cimodel1))), grid(none) xtitle("Predicted Number of Days", size(small) margin(t=2)) ylabel(1 `" "Model D3" "Interquartile Change" "' 2 `" "Model D3" "Interdecile Change" "' 3 `" "Model D4" "Interquartile Change" "' 4 `" "Model D4" "Interdecile Change" "', labsize(small) noticks) mlabel format(%9.0f) mlabposition(12) mlabsize(vsmall) xlabel(-200(100)200, angle(0) labsize(small) format(%9.0f))   msymbol(o) mcolor(black) msize(small) title("FIGURE D2", size(small)) ciopts(lcolor(black)) legend(off) subtitle("Marginal Differential Effect of Presidential Loyalty on Median Appointee Tenure" "[Unconditional Additive Effect]", size(small)) xline(0, lcolor(red%40) lpattern(dash))

graph save "Graph" "C:\Users\Jason\Dropbox\Jason Byers\Co-Authored Projects\Projects with George Krause\Krause Projects\Confirmation Dynamics Project\Appointee Tenure Project\Jason Byers\March 2023\DART (PRQ)\Graphics\FigureD2.gph", replace




******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************


log close

